#include "VIN_SoundManager.h"
#include "mathlib.h"
#include "cgame.h"

VIN_SoundManager::VIN_SoundManager()
{
	Death1 = Death2 = Punch1 = Punch2 = Punch3 = -1;
	Woosh1 = Woosh2 = Woosh3 = Hurt1 = Hurt2 = Hurt3 = -1;
	Gunshot1 = Gunshot2 = Gunshot3 = MenuSelect = MenuConfirm = -1;
	Pickup = Explosion = Alarm = Collect = -1;
	CityID = TitleBGM = MenuBGM = CreditBGM = Highscores = -1;

}
VIN_SoundManager::~VIN_SoundManager()
{

}
VIN_SoundManager::VIN_SoundManager(const VIN_SoundManager& copy)
{

}
//VIN_SoundManager::VIN_SoundManager &operator=(const VIN_SoundManager& assign)
//{
//
//	return this;
//}

VIN_SoundManager* VIN_SoundManager::GetInstance()
{
	static VIN_SoundManager instance;
	return& instance;
}


bool VIN_SoundManager::Startup(void)
{
	fmod = CSGD_FModManager::GetInstance();
	CityID = fmod->LoadSound("resource/sound/Level1.mp3", FMOD_LOOP_NORMAL);
	Highscores = fmod->LoadSound("resource/sound/highscores.mp3", FMOD_LOOP_NORMAL);
	CreditBGM = fmod->LoadSound("resource/sound/Credits.mp3", FMOD_LOOP_NORMAL);
	TitleBGM = fmod->LoadSound("resource/sound/TitleMenu.mp3", FMOD_LOOP_NORMAL);
	//HighScoreBGM = fmod->LoadSound("resource/sound/TitleMenu.mp3", FMOD_LOOP_NORMAL);
	MenuBGM = fmod->LoadSound("resource/sound/othermenus.mp3", FMOD_LOOP_NORMAL);
	Punch1 = fmod->LoadSound("resource/sound/punch1.wav");
	Punch2 = fmod->LoadSound("resource/sound/punch2.wav");
	Punch3 = fmod->LoadSound("resource/sound/punch3.wav");
	Death1 = fmod->LoadSound("resource/sound/Death1.wav");
	Death2 = fmod->LoadSound("resource/sound/Death2.wav");
	Explosion = fmod->LoadSound("resource/sound/explosion.wav");
	MenuConfirm = fmod->LoadSound("resource/sound/menuconfirm.wav");
	MenuSelect = fmod->LoadSound("resource/sound/menuselect.wav");
	Woosh1 = fmod->LoadSound("resource/sound/Punchwoosh1.wav");
	Woosh2 = fmod->LoadSound("resource/sound/Punchwoosh2.wav");
	Woosh3 = fmod->LoadSound("resource/sound/Punchwoosh3.wav");
	Alarm = fmod->LoadSound("resource/sound/Alarm.wav", FMOD_LOOP_NORMAL);

	while(CityID == -1)
	{

	}

	return true;
}
void VIN_SoundManager::Shutdown(void)
{
	fmod = CSGD_FModManager::GetInstance();
	fmod->ShutdownFModManager();
}

void VIN_SoundManager::PlayBGM(int Screen)
{
	StopAllSounds();
	switch(Screen)
	{
	case 1:
		fmod->PlaySound(TitleBGM);
		break;
	case 2:
		fmod->PlaySound(CreditBGM);
		break;
	case 3:
		fmod->PlaySound(MenuBGM);
		break;
	case 4:
		fmod->PlaySound(CityID);
		break;
	case 5:
		fmod->PlaySound(Highscores);
		break;

	}
}
void VIN_SoundManager::PlaySound(int SoundID)
{
	if(SoundID != -1)
		fmod->PlaySound(SoundID);
}

void VIN_SoundManager::PlayPunch()
{
	fmod = CSGD_FModManager::GetInstance();

	//int randpunch = RandInt(1, 3);
	int randpunch = rand() % 3 + 1;
	switch(randpunch)
	{
	case 1:
		if(!fmod->IsSoundPlaying(Punch1))
			fmod->PlaySound(Punch1);
		break;
	case 2:
		if(!fmod->IsSoundPlaying(Punch2))
			fmod->PlaySound(Punch2);
		break;
	case 3:
		if(!fmod->IsSoundPlaying(Punch3))
			fmod->PlaySound(Punch3);
		break;
	}
}

void VIN_SoundManager::PlayWoosh()
{
	int randpunch = rand() % 3 + 1;
	switch(randpunch)
	{
	case 1:
		fmod->PlaySound(Woosh1);
		break;
	case 2:
		fmod->PlaySound(Woosh2);
		break;
	case 3:
		fmod->PlaySound(Woosh3);
		break;
	}
}
void VIN_SoundManager::PlayDeath()
{
	int randdeath = rand() % 2+1;
	switch(randdeath)
	{
	case 1:
		fmod->PlaySound(Death1);
		break;
	case 2:
		fmod->PlaySound(Death2);
		break;
	}


}
void VIN_SoundManager::PlayExplosion()
{
	fmod->PlaySound(Explosion);
}
void VIN_SoundManager::PlayMenuSelect()
{
	fmod->PlaySound(MenuSelect);
}
void VIN_SoundManager::PlayMenuConfirm()
{
	fmod->PlaySound(MenuConfirm);
}
void VIN_SoundManager::PlayAlarm()
{
	if(!fmod->IsSoundPlaying(Alarm))
		fmod->PlaySound(Alarm);	
}
void VIN_SoundManager::PlayPickup()
{

}
void VIN_SoundManager::PlayKnifeSlash()
{

}
void VIN_SoundManager::PlayCollect()
{


}
void VIN_SoundManager::PlayPlayerDeath()
{

}

void VIN_SoundManager::PlayCityAmbient()
{

}
void VIN_SoundManager::PlayFarmAmbient()
{

}
void VIN_SoundManager::PlayDockAmbient()
{

}
void VIN_SoundManager::PlayFactoryAmbient()
{

}

void VIN_SoundManager::StopAllSounds()
{
	// Music
	if(CityID != -1 && fmod->IsSoundPlaying(CityID))
		fmod->StopSound(CityID);

	if(TitleBGM != -1 && fmod->IsSoundPlaying(TitleBGM))
		fmod->StopSound(TitleBGM);

	if(MenuBGM != -1 && fmod->IsSoundPlaying(MenuBGM))
		fmod->StopSound(MenuBGM);

	if(CreditBGM != -1 && fmod->IsSoundPlaying(CreditBGM))
		fmod->StopSound(CreditBGM);

	if(Highscores != -1 && fmod->IsSoundPlaying(Highscores))
		fmod->StopSound(Highscores);

	// Sounds
	if(Explosion != -1 && fmod->IsSoundPlaying(Explosion))
		fmod->StopSound(Explosion);

	if(Woosh1 != -1 && fmod->IsSoundPlaying(Woosh1))
		fmod->StopSound(Woosh1);

	if(Woosh2 != -1 && fmod->IsSoundPlaying(Woosh2))
		fmod->StopSound(Woosh2);

	if(Woosh3 != -1 && fmod->IsSoundPlaying(Woosh3))
		fmod->StopSound(Woosh3);

	if(Punch1 != -1 && fmod->IsSoundPlaying(Punch1))
		fmod->StopSound(Punch1);

	if(Punch2 != -1 && fmod->IsSoundPlaying(Punch2))
		fmod->StopSound(Punch2);

	if(Punch3 != -1 && fmod->IsSoundPlaying(Punch3))
		fmod->StopSound(Punch3);

	if(Death1 != -1 && fmod->IsSoundPlaying(Death1))
		fmod->StopSound(Death1);

	if(Death2 != -1 && fmod->IsSoundPlaying(Death2))
		fmod->StopSound(Death2);

	if(Death2 != -1 && fmod->IsSoundPlaying(Alarm))
		fmod->StopSound(Alarm);


}
void VIN_SoundManager::StopSound(int SoundID)
{
	if( SoundID != -1)
	{
		fmod->StopSound(SoundID);
	}
}

void VIN_SoundManager::ResetAllSounds()
{

}
void VIN_SoundManager::ResetSound(int SoundID)
{

	if( SoundID != -1)
	{
		fmod->StopSound(SoundID);
		fmod->ResetSound(SoundID);
	}
}

void VIN_SoundManager::SetBGMVolume(float volume)
{
	fmod->SetVolume(CityID, volume);
	fmod->SetVolume(TitleBGM, volume);
	fmod->SetVolume(CreditBGM, volume);
	fmod->SetVolume(MenuBGM, volume);
	fmod->SetVolume(Highscores, volume);
}

void VIN_SoundManager::SetSFXVolume(float volume)
{
	fmod->SetVolume(Punch1, volume);
	fmod->SetVolume(Punch2, volume);
	fmod->SetVolume(Punch3, volume);
	fmod->SetVolume(Death1, volume);
	fmod->SetVolume(Death2, volume);
	fmod->SetVolume(Explosion, volume);
	fmod->SetVolume(MenuConfirm, volume);
	fmod->SetVolume(MenuSelect, volume);
	fmod->SetVolume(Woosh1, volume);
	fmod->SetVolume(Woosh2, volume);
	fmod->SetVolume(Woosh3, volume);

}